package com.cskaoyan.shopping.api;

import com.cskaoyan.mall.commons.constant.SysRetCodeConstants;
import com.cskaoyan.mall.commons.result.ServiceCallResponse;
import com.cskaoyan.mall.commons.result.ServiceCallResponseUtil;
import com.cskaoyan.mall.dto.*;
import com.cskaoyan.shopping.service.ICartOrderService;
import com.cskaoyan.shopping.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @auther cskaoyan
 * @date 2022/8/24:14:56
 */
@RestController
public class OrderApiImpl {

    @Autowired
    IProductService productService;

    @Autowired
    ICartOrderService iCartOrderService;


    @GetMapping(value = "/rpc/product/detail")
    public ServiceCallResponse<ProductDetailDto> getProductDetail(@RequestParam("id") Long id) {
        ProductDetailDto productDetail = productService.getProductDetail(id);
        ServiceCallResponseUtil<ProductDetailDto> responseUtil = new ServiceCallResponseUtil<>();
        return responseUtil.ok(productDetail);
    }

    @PostMapping(value = "/rpc/cart/items")
    public ClearCartItemServiceResponse clearCartItemByUserID(@RequestBody ClearCartItemRequest request) {
        iCartOrderService.clearCartItemByUserID(request);
        ClearCartItemServiceResponse clearCartItemServiceResponse = new ClearCartItemServiceResponse();
        clearCartItemServiceResponse.setCode(SysRetCodeConstants.SERVICE_CALL_SUCCESS.getCode());
        clearCartItemServiceResponse.setMsg(SysRetCodeConstants.SERVICE_CALL_SUCCESS.getMessage());
        clearCartItemServiceResponse.setCallData("成功");

        return clearCartItemServiceResponse;
    }
}
